package com.kevis.zhunblog.api.controller;

import com.github.pagehelper.PageInfo;
import com.kevis.zhunblog.api.vo.R;
import com.kevis.zhunblog.core.dto.PageDomain;
import com.kevis.zhunblog.core.dto.query.CommonInfoQuery;
import com.kevis.zhunblog.core.entities.ArticleEntity;
import com.kevis.zhunblog.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin(origins = "http://127.0.0.1:5500")
@RestController("/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @GetMapping("test")
    public String test() {
        return "hello";
    }

    @GetMapping("/kk/test")
    public String test1() {
        return "hello1";
    }

    @PostMapping("/list")
    public Object list(@RequestParam("page") Integer currpage) {
        PageDomain pageDomain = new PageDomain();
        pageDomain.setPage(currpage);
        CommonInfoQuery query = new CommonInfoQuery();
        PageInfo<ArticleEntity> pageList = articleService.getPageList(query, pageDomain);
        return R.success(pageList) ;
    }

    @PostMapping("/{id}")
    public Object details(@PathVariable("id")Integer id){
        return R.success(articleService.getById(id));
    }

}
